package isp.apps.example.shoppingcart.persistence.hibernate;

import isp.apps.example.shoppingcart.domain.ShippingOption;
import isp.apps.example.shoppingcart.persistence.PersistenceManagerFactory;
import isp.apps.example.shoppingcart.persistence.ShippingOptionsDirectory;

import isp.utils.cjis.persistence.PersistenceException;

import isp.utils.cjis.persistence.PersistenceManager;

import java.util.Collections;
import java.util.LinkedList;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class HibernateShippingOptionsDirectory implements ShippingOptionsDirectory
{
  private PersistenceManager persistenceManager = PersistenceManagerFactory.getPersistenceManager();

  private static final Log log = LogFactory.getLog(HibernateShippingOptionsDirectory.class);
  public HibernateShippingOptionsDirectory()
  {
  }

  public List getAllOptions()
  {
    try
    {
      return persistenceManager.find("get.allOptions", Collections.EMPTY_LIST);
    }
    catch (PersistenceException pe)
    {
      log.error(pe, pe);
      return null;
    }
  }

  public List getValidOptions()
  {
    try
    {
      return persistenceManager.find("get.validOptions", Collections.EMPTY_LIST);
    }
    catch (PersistenceException pe)
    {
      log.error(pe, pe);
      return null;
    }
  }

  public ShippingOption getOptionById(Integer id)
  {
    try
    {
      return (ShippingOption) persistenceManager.load(ShippingOption.class, id);
    }
    catch (PersistenceException pe)
    {
      log.error(pe, pe);
      return null;
    }
  }
}
